import Promise from "../promise";

// 用于测试Promise.race
let promise1 = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve("第1个异步操作成功了！");
    }, 1000);
});

let promise2 = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve("第2个异步操作成功了！");
        // reject("第2个异步操作失败了！");
    }, 1000);
});

let promise3 = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve("第3个异步操作成功了！");
    }, 1000);
});


// race: [p1,p2,p3] 有1个promise率先改变状态race执行完毕，then()的结果取决于这个率先改变状态的promise，可以是成功的也可以是失败的。
Promise.race([promise1, promise2, promise3]).then((resolveData) => {
    console.log(`resolveData: `, resolveData);
}, (rejectData) => {
    console.log(`rejectData: `, rejectData);
});

